import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from "@nestjs/common";
import { RoleApiService } from './role-api.service';
import { CreateRoleApiDto } from './dto/create-role-api.dto';
import { UpdateRoleApiDto } from './dto/update-role-api.dto';
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";
import { RoleAddApiDto } from "@/modules/system/role-api/dto/role-add-api.dto";
import { GetMenuIdByRoleIdDto } from "@/modules/system/role-menu/dto/getMenuIdByRoleId.dto";
import { GetApiIdByRoleIdDto } from "@/modules/system/role-api/dto/getApiIdByRoleId.dto";

@Controller('system/role-api')
@ApiBearerAuth()
@ApiTags("角色设置 接口权限 相关")
export class RoleApiController {
  constructor(private readonly roleApiService: RoleApiService) {}

  @Post()
  create(@Body() createRoleApiDto: CreateRoleApiDto) {
    return this.roleApiService.create(createRoleApiDto);
  }

  @Get()
  findAll() {
    return this.roleApiService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.roleApiService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateRoleApiDto: UpdateRoleApiDto) {
    return this.roleApiService.update(+id, updateRoleApiDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.roleApiService.remove(+id);
  }
  @Post("roleAddApi")
  @ApiOperation({ summary: "角色分配Api权限" })
  roleAddMenu(@Body() roleAddApiDto: RoleAddApiDto) {
    return this.roleApiService.roleAddApi(roleAddApiDto);
  }
  
  @Post("getApiIdByRoleId")
  @ApiOperation({ summary: "获取当前角色下的所有菜单" })
  getApiIdByRoleId(@Query() getApiIdByRoleIdDto: GetApiIdByRoleIdDto) {
    return this.roleApiService.getApiIdByRoleId(getApiIdByRoleIdDto);
  }
}
